package com.多线程.InetAddress;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * InetAddress类的使用，常用APi
 */

public class InetAddressDemo1 {
    public static void main(String[] args) throws Exception {
        //1.创建一个InetAddress对象
        InetAddress address=InetAddress.getLocalHost();//获取本地地址对象
        System.out.println(address.getHostName());//获取主机名
        System.out.println(address.getHostAddress());//获取ip地址

        //2.获取域名ip对象
        InetAddress address1=InetAddress.getByName("www.baidu.com");//根据百度的域名获取InetAddress对象
        System.out.println(address1.getHostName());
        System.out.println(address1.getHostAddress());

        //3.获取公网IP对象
        InetAddress address2=InetAddress.getByName("112.80.248.75");
        System.out.println(address2.getHostName());
        System.out.println(address2.getHostAddress());

        //判断两个网络是否连通
        System.out.println(address.isReachable(5000));//timeout是等待时间


    }
}
